const app = getApp();
Component({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    iconList: [{
      icon: 'cardboardfill',
      color: 'red',
      badge: 120,
      name: 'VR'
    }, {
      icon: 'recordfill',
      color: 'orange',
      badge: 1,
      name: '录像'
    }, {
      icon: 'picfill',
      color: 'yellow',
      badge: 0,
      name: '图像'
    }, {
      icon: 'noticefill',
      color: 'olive',
      badge: 22,
      name: '通知'
    }, {
      icon: 'upstagefill',
      color: 'cyan',
      badge: 0,
      name: '排行榜'
    }, {
      icon: 'clothesfill',
      color: 'blue',
      badge: 0,
      name: '皮肤'
    }, {
      icon: 'discoverfill',
      color: 'purple',
      badge: 0,
      name: '发现'
    }, {
      icon: 'questionfill',
      color: 'mauve',
      badge: 0,
      name: '帮助'
    }, {
      icon: 'commandfill',
      color: 'purple',
      badge: 0,
      name: '问答'
    }, {
      icon: 'brandfill',
      color: 'mauve',
      badge: 0,
      name: '版权'
    }],
    gridCol:3,
    skin: false,
    friends:[
    ],
    friends_detail:[
      
    ],
    a:[1,3],
    b:["20:05","15:32"]
  },
  properties:{
    newMessages:Array
  },
  options:{
    addGlobalClass: true,
  },

  methods:{
      chat(e){
        wx.navigateTo({
          url: '../lt/chata/chata?userId='+e.currentTarget.dataset.target+"&&name="+e.currentTarget.dataset.name+"&&sex="+e.currentTarget.dataset.sex,
        })
      },
      test(){
        return "33"
      },
  },
  test(){
    return "33"
  },
  lifetimes:{
    
  attached:function(){
    wx.cloud.database().collection('yw_exchange').where({openid:app.globalData.userInfo._openid}).get().then(res=>{
      let res2 = res.data
        res2.forEach(res3=>{
          wx.getStorage({
            key: res3.openid2,
            success:res=>{
              res3.lastMessage=res.data.slice(-1)[0]
            },
            fail:err=>{
              console.log(err)
            },
            complete:res=>{
              this.setData({
                friends:this.data.friends.concat(res3)
              })
            }
          })
        })
    })
    
    // wx.getStorage({
    //   key: 'Messages',
    //   success:res=>{
    //       this.setData({
    //         friends:res.data
    //       })
    //   },
    //   fail:err=>{
    //     console.log(err)
    //   }
    // })
  },
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  gridchange: function (e) {
    this.setData({
      gridCol: e.detail.value
    });
  },
  gridswitch: function (e) {
    this.setData({
      gridBorder: e.detail.value
    });
  },
  menuBorder: function (e) {
    this.setData({
      menuBorder: e.detail.value
    });
  },
  menuArrow: function (e) {
    this.setData({
      menuArrow: e.detail.value
    });
  },
  menuCard: function (e) {
    this.setData({
      menuCard: e.detail.value
    });
  },
  switchSex: function (e) {
    this.setData({
      skin: e.detail.value
    });
  },

  // ListTouch触摸开始
  ListTouchStart(e) {
    this.setData({
      ListTouchStart: e.touches[0].pageX
    })
  },

  // ListTouch计算方向
  ListTouchMove(e) {
    this.setData({
      ListTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > 0 ? 'right' : 'left'
    })
  },

  // ListTouch计算滚动
  ListTouchEnd(e) {
    if (this.data.ListTouchDirection =='left'){
      this.setData({
        modalName: e.currentTarget.dataset.target
      })
    } else {
      this.setData({
        modalName: null
      })
    }
    this.setData({
      ListTouchDirection: null
    })
  },
  onLoad(){
      console.log(123)
  },
  onShow(){
    console.log(44)
    // wx.getStorage({
    //   key: 'Messages',
    //   success:res=>{
    //       this.setData({
    //         friends:res.data
    //       })
    //       console.log(friends)
    //   },
    //   fail:err=>{
    //     console.log(err)
    //   }
    // })
  },

})